package site.luojie.utils;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @Description: 获取连接工具类
 * @Author jie.luo
 * @Create: 2020-05-02 08:05
 **/
public class ConnectionUtils {
    private ThreadLocal<Connection> connectionThreadLocal = new ThreadLocal<>();

    public Connection getCurrentThreadConnection() throws SQLException {
        Connection connection = connectionThreadLocal.get();
        if (null == connection) {
            connection = DruidDataSourceUtil.getInstance().getConnection();
            connectionThreadLocal.set(connection);
        }
        return connection;
    }

}
